const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Prefab)
    ball:cc.Prefab=null;

    onLoad () {
        //物理组件管理器
        let manage=cc.director.getPhysicsManager();

        //启动物理组件
        manage.enabled=true;

    }

    //节点加载到场景中运行的函数
    start () {
        //键盘点击事件
        this.node.on('keydown',this.onKeydown,this);
        //触摸事件
        this.node.on(cc.Node.EventType.TOUCH_START,this.onTouchStart,this);
    }

    // update (dt) {}

    onKeydown(e:cc.Event.EventKeyboard){
        cc.log('onKeydown');
        let ballNode:cc.Node=cc.instantiate(this.ball);
        ballNode.position=cc.v3();
    }

    onTouchStart(e:cc.Event.EventTouch){
        cc.log('onTouchStart');
        let c2=this.node.convertTouchToNodeSpaceAR(e.touch);
        let ballNode:cc.Node=cc.instantiate(this.ball);
        ballNode.position=cc.v3(c2);
        this.node.addChild(ballNode);
    }
}
